<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/11/26
 * Time: 上午9:20
 */

class ApiMenu {

    public static function all($params){
        $result = ModMenu::model()->select();

        return $result;
    }

    public static function get($params){
        $result = array();
        if(PubFunc::checkEmpty($params, array('userid'))) return $result;

//        $gameId = ApiGame::getGameIdBySrc($params['game']);
//        $platformId = ApiGame::getPlatformIdBySrc($params['platform']);

        $tmp = AccAuth::getRoleMenu($params['userid']);

        $menu = $function = array();
        foreach($tmp as $v){
            $tmp = $v;
            unset($tmp['Function']);
            if(!empty($tmp['MenuUrl'])){
                $tmp['MenuUrl'] = html_entity_decode($tmp['MenuUrl']);
                $function[$tmp['MenuUrl']] = $tmp['MenuUrl'];
            }

            $menu[$v['MenuID']] = $tmp;

            if(!empty($v['Function'])){
                foreach(explode("\r\n", $v['Function']) as $vv){
                    $url = html_entity_decode(trim($vv));
                    $function[$url] = $url;
                }
            }
        }

        PubFunc::getDepth($menu, '0', 'MenuID', 'ParentID');

        return array(
            'Menu'      => $menu,
            'Function'  => array_values($function)
        );
    }
} 